package framework.mvc;

import framework.account.IAccount;
import framework.command.CommandManager;
import framework.command.DebtCommand;
import framework.command.ICommand;

import javax.swing.*;


public class DebtDialog extends javax.swing.JDialog {


    private AFincoView view;

    private IAccount account;

    public DebtDialog(AFincoView parent, String actionName, IAccount account) {
        super(parent);

        this.account = account;

        setTitle("Charge Account");
        setModal(true);
        getContentPane().setLayout(null);
        setSize(277, 134);
        setVisible(false);
        JLabel1.setText("Name");
        getContentPane().add(JLabel1);
        JLabel1.setForeground(java.awt.Color.black);
        JLabel1.setBounds(12, 12, 48, 24);
        JLabel2.setText("Amount");
        getContentPane().add(JLabel2);
        JLabel2.setForeground(java.awt.Color.black);
        JLabel2.setBounds(12, 36, 48, 24);
        JTextField_NAME.setEditable(false);
        getContentPane().add(JTextField_NAME);
        JTextField_NAME.setBounds(84, 12, 156, 20);
        getContentPane().add(JTextField_AMT);
        JTextField_AMT.setBounds(84, 36, 156, 20);
        JButton_OK.setText("OK");
        JButton_OK.setActionCommand("OK");
        getContentPane().add(JButton_OK);
        JButton_OK.setBounds(48, 84, 84, 24);
        JButton_Calcel.setText("Cancel");
        JButton_Calcel.setActionCommand("Cancel");
        getContentPane().add(JButton_Calcel);
        JButton_Calcel.setBounds(156, 84, 84, 24);
        //}}
        JTextField_NAME.setText(account.getAccountNo());

        //{{REGISTER_LISTENERS
        SymAction lSymAction = new SymAction();
        JButton_OK.addActionListener(lSymAction);
        JButton_Calcel.addActionListener(lSymAction);
        //}}
    }


    //{{DECLARE_CONTROLS
    JLabel JLabel1 = new JLabel();
    JLabel JLabel2 = new JLabel();
    JTextField JTextField_NAME = new JTextField();
    JTextField JTextField_AMT = new JTextField();
    JButton JButton_OK = new JButton();
    JButton JButton_Calcel = new JButton();

    class SymAction implements java.awt.event.ActionListener {
        public void actionPerformed(java.awt.event.ActionEvent event) {
            Object object = event.getSource();
            if (object == JButton_OK)
                JButtonOK_actionPerformed(event);
            else if (object == JButton_Calcel)
                JButtonCalcel_actionPerformed(event);
        }
    }

    void JButtonOK_actionPerformed(java.awt.event.ActionEvent event) {
        ICommand command = new DebtCommand(account, Float.valueOf(JTextField_AMT.getText()));
        CommandManager.getInstance().submit(command);
        dispose();
    }

    void JButtonCalcel_actionPerformed(java.awt.event.ActionEvent event) {
        dispose();
    }
}